const defaultOptions = {
    selector: '#poster'
};

function Poster(options = {}, that) {
    options = {
        ...defaultOptions,
        ...options,
    };

    const pages = getCurrentPages();
    let ctx = pages[pages.length - 1];
    if (that) ctx = that
    const poster = ctx.selectComponent(options.selector);
    //delete options.selector;

    return poster;
};

Poster.getTextHeight = (text, that, pixelRatio = 1) => {
	let height = 0
	const poster  = Poster({}, that);
	if (!poster) {
	    console.error('请设置组件的id="poster"!!!');
		height = 0
	} else {
		let lines = Poster({}, that).getTextLines(pixelRatio, text)
		let fontHeight = text.lineHeight || text.fontSize;
		height = lines.length * fontHeight
	}
	return height
}

Poster.getTextBounds = (target, text, that, pixelRatio = 1) => {
	let textBounds = []
	const poster  = Poster({}, that);
	if (!poster) {
	    console.error('请设置组件的id="poster"!!!');
		textBounds = []
	} else {
		textBounds = Poster({}, that).getTextBounds(pixelRatio, target, text)
	}
	return textBounds
}

Poster.create = (reset = false, that) => {
    const poster  = Poster({}, that);
    if (!poster) {
        console.error('请设置组件的id="poster"!!!');
    } else {
        return Poster({}, that).onCreate(reset);
    }
}

export default Poster
